<%@page import="com.jacap.*"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" name="author" content="20201212杨铖宇">
<title>Jacap</title>
<!-- 引入css、js -->
<link rel="stylesheet" href="css/log.css">
<link rel="stylesheet" href="https://www.jq22.com/jquery/bootstrap-4.2.1.css">
<script src="js/login.js"></script>
<script src="js/jquery.js"></script>
<script src="js/lin_search.js"></script>
<script src="js/bootstrap.js"></script>
<style>
  #lin {
    margin: 20px 0;
    height: 30px;
    padding: 5px;
    box-sizing: border-box;
  }
  .names {
    width: 120px;
    margin-bottom: 0px;
</style>
</head>
<body>
	<!--背景变换-->
	<div class="slideshow">
		<div class="slideshow-image"
			style="background-image: url('img/wallhaven1.png')"></div>
		<div class="slideshow-image"
			style="background-image: url('img/wallhaven3.png')"></div>
		<div class="slideshow-image"
			style="background-image: url('img/wallhaven4.png')"></div>
		<div class="slideshow-image"
			style="background-image: url('img/wallhaven5.png')"></div>
	</div>
	<!--导航栏-->
	<ul>
		<li><a class="active" href="https://ycy20201212.github.io/">Home</a></li>
		<li><a href="https://www.sohu.com/">News</a></li>
		<li><a href="https://www.cnblogs.com/20201212ycy/">Contact</a></li>
		<li><a href="Log.jsp">日志审计</a></li>
		<li><a href="Usb.jsp">USB审计</a></li>
		<li style="float: right"><a href="About.html">About</a></li>
	</ul>
	<!--主体-->
	<div class="container switch">
		<form action="JacapGet" class="form" align="center">
			
			<table id="pageListTable">
				<thead class="fixed_header">
					<tr>
						<th>
							<select class="form-control names" id="select">
							  <option>数据包类型</option>
						      <option>TCP</option>
						      <option>UDP</option>
							  <option>ICMP</option>
						      <option>IP</option>
						      <option>ARP</option>
						    </select>
					    </th>
						<th>数据包长度len</th>
						<th>时间戳sec(秒)</th>
						<th>时间戳usec(毫秒)</th>
						<th>源IP</th>
						<th>目的IP</th>
						<th>协议protocol</th>
						<th>优先权priority</th>
						<th>生存时间hop</th>
						<th>片偏移offset</th>
						<th>标识ident</th>
						<th>源端口src_port</th>
						<th>目的端口dst_port</th>
						<th>系统时间systime</th>
					</tr>
				</thead>
				<tbody id="pageListTableBody">
					<%
					ArrayList<Jacaps> list = (ArrayList<Jacaps>)request.getAttribute("jacaplist");
						      	if(list == null || list.toString().equals("[]")){%>
						      		<h3>暂无流量数据</h3>
						      	<%}
						      	else{
									for (Jacaps l : list) {
					%>
					<tr>
						<td><%=l.getType()%></td>
						<td><%=l.getLen()%></td>
						<td><%=l.getSec()%></td>
						<td><%=l.getUsec()%></td>
						<td><%=l.getSrc_ip()%></td>
						<td><%=l.getDst_ip()%></td>
						<td><%=l.getProtocol()%></td>
						<td><%=l.getPriority()%></td>
						<td><%=l.getHop()%></td>
						<td><%=l.getOffset()%></td>
						<td><%=l.getIdent()%></td>
						<td><%=l.getSrc_port()%></td>
						<td><%=l.getDst_port()%></td>
						<td><%=l.getSystime()%></td>					
					</tr>
					<%
					}}
					%>
				</tbody>
			</table>
			<p>
			<% String identity = request.getParameter("identity");
			if (list == null || list.toString().equals("[]")) {%>
				捕获数据包：
				<input type="text" name="seconds" id="seconds" value="6" style="width:30px" οnkeyup="value=value.replace(/[^\-?\d.]/g,'')"/>
				个&emsp;
				<input type="text" name="identity" value="<%=identity%>" style="display:none">
				<input type="submit" value="开始审计">
			</p>
			<%}else{
					int pagenum = Integer.parseInt(request.getParameter("pagenum"));	// 页数
				if("Administrator".equals(identity)){
			%>
					<a href="JacapClose?identity=<%=identity%>">断开网络</a>&emsp;&emsp;
			<%}else{ %>			
				捕获数据包：
				<input type="text" name="seconds" id="seconds" value="6" style="width:30px" οnkeyup="value=value.replace(/[^\-?\d.]/g,'')"/>
				个&emsp;
				<input type="text" name="identity" value="<%=identity%>" style="display:none">
				<input type="submit" value="开始审计">
				<p><a href="Jacaplist?pagenum=<%=pagenum-1%>&identity=<%=identity%>">数据库分页上一页</a>&emsp;第 <strong><%=pagenum%></strong> 页&emsp;<a href="Jacaplist?pagenum=<%=pagenum+1%>&identity=<%=identity%>">数据库分页下一页</a></p>
			<%}}%>
			<div id="pageBox">&emsp;&emsp;
				<span id="spanFirst">首页</span> 
				<span id="spanPre">上一页</span> 
				<span id="spanNext">下一页</span> 
				<span id="spanLast">尾页</span> 
				<br>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
				第 <strong id="spanPageNum"></strong> 页/共 <strong id="spanTotalPage"></strong>	页
			</div>
	</div>
	</form>
	</div>

	<script>
		// 表2
	    $('#select').on('change', function () {
	      var content = $('#select') // 下拉框
	      var table2 = $('#pageListTable')
	      new Search(table2, content, '#6332f6')
	    })
		
		var theUL = document.getElementById("pageListTableBody");
		var totalPage = document.getElementById("spanTotalPage");
		var pageNum = document.getElementById("spanPageNum"); //获取当前页<span>
		var spanPre = document.getElementById("spanPre"); //获取上一页<span>
		var spanNext = document.getElementById("spanNext"); //获取下一页<span>
		var spanFirst = document.getElementById("spanFirst"); //获取第一页<span>
		var spanLast = document.getElementById("spanLast"); //获取最后一页<span>
		var numberRowsInTable = theUL.getElementsByTagName("tr").length; //记录总条数
		var pageSize = 4; //每页显示的记录条数
		var page = 1; //当前页，默认第一页

		//下一页
		function next() {
			hideTable();
			currentRow = pageSize * page;
			maxRow = currentRow + pageSize;
			if (maxRow > numberRowsInTable)
				maxRow = numberRowsInTable;
			for (var i = currentRow; i < maxRow; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = '';
			}
			page++;
			if (maxRow == numberRowsInTable) {
				nextText();
				lastText();
			}
			showPage();
			preLink();
			firstLink();
		}

		//上一页
		function pre() {
			hideTable();
			page--;
			currentRow = pageSize * page;
			maxRow = currentRow - pageSize;
			if (currentRow > numberRowsInTable)
				currentRow = numberRowsInTable;
			for (var i = maxRow; i < currentRow; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = '';
			}
			if (maxRow == 0) {
				preText();
				firstText();
			}
			showPage();
			nextLink();
			lastLink();
		}

		//第一页
		function first() {
			hideTable();
			page = 1;
			for (var i = 0; i < pageSize; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = '';
			}
			showPage();
			firstText();
			preText();
			nextLink();
			lastLink();
		}

		//最后一页
		function last() {
			hideTable();
			page = pageCount();
			currentRow = pageSize * (page - 1);
			for (var i = currentRow; i < numberRowsInTable; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = '';
			}
			showPage();
			preLink();
			nextText();
			firstLink();
			lastText();
		}

		function hideTable() {
			for (var i = 0; i < numberRowsInTable; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = 'none';
			}
		}

		function showPage() {
			pageNum.innerHTML = page;
		}

		//总共页数
		function pageCount() {
			return Math.ceil(numberRowsInTable / pageSize);
		}
		//显示链接
		function preLink() {
			spanPre.innerHTML = "<a href='javascript:pre();'>上一页</a>";
		}
		function preText() {
			spanPre.innerHTML = "上一页";
		}
		function nextLink() {
			spanNext.innerHTML = "<a href='javascript:next();'>下一页</a>";
		}
		function nextText() {
			spanNext.innerHTML = "下一页";
		}
		function firstLink() {
			spanFirst.innerHTML = "<a href='javascript:first();'>首页</a>";
		}
		function firstText() {
			spanFirst.innerHTML = "首页";
		}
		function lastLink() {
			spanLast.innerHTML = "<a href='javascript:last();'>末页</a>";
		}
		function lastText() {
			spanLast.innerHTML = "末页";
		}

		//隐藏
		function hide() {
			for (var i = pageSize; i < numberRowsInTable; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = 'none';
			}
			totalPage.innerHTML = pageCount();
			pageNum.innerHTML = '1';
			nextLink();
			lastLink();
		}
		hide();
	</script>

</body>
</html>